package io.kiki.task.server.job.task.support.generator.task;

import io.kiki.task.common.core.enums.JobTaskTypeEnum;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ConcurrentHashMap;

@Slf4j
public final class JobTaskGeneratorFactory {

    private static final ConcurrentHashMap<JobTaskTypeEnum, JobTaskGenerator> CACHE = new ConcurrentHashMap<>();

    public static void registerTaskInstance(JobTaskTypeEnum taskInstanceType, JobTaskGenerator generator) {
        CACHE.put(taskInstanceType, generator);
    }

    public static JobTaskGenerator getTaskInstance(Integer type) {
        return CACHE.get(JobTaskTypeEnum.valueOf(type.toString()));
    }
}
